package files_examples;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;

public class ForFiles {

	public static void main(String[] args)throws FileNotFoundException, IOException {
		   
		BufferedReader reader = new BufferedReader(new FileReader("src\\for_example.txt"));

		   StringBuilder sb = new StringBuilder();
		   String line = null;
		   while ( (line = reader.readLine()) != null) {
		     sb.append(line).append("\n");
		   }
		   reader.close();
		   String[] words = sb.toString().split("\\s+");
		   System.out.println("Total words:" + words.length);
		
		   BufferedWriter out = new BufferedWriter(new FileWriter("src\\for_example11.txt"));
		 
		/*   Scanner sc = new Scanner(new File("src\\for_example.txt"));
		   while (sc.hasNextLine()) {
		     String line1 = sc.nextLine();
		     out.write(line1+",");
		   }*/
		   for(int i=0; i<=words.length-1; i++ ){
		   out.write(words[i]+" ");}
		   out.close();
		  // sc.close();
		   
		  /*long ts = System.nanoTime();

		   String buff = "";
		   //2 StringBuffer buff = new StringBuffer();
		   //3 StringBuilder buff = new StringBuilder();

		   for (String word : words) {
		    buff += word + " ";
		    //2&3 buff.append(word).append(" ");
		   }

		   long te =System.nanoTime();*/

		   System.out.println("Complete, lenght:" );

		  }

		
		 

	}


